{include file='common/head' /}
<body>
<script src="/static/pluring/jq.js"></script>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <input type="hidden" name="id" value="{$data.id|default=''}">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    银行名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="bank_name" required="" autocomplete="off" class="layui-input" value="{$data.bank_name|default=''}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    银行卡号
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="card" required="" autocomplete="off" class="layui-input" value="{$data.card|default=''}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    卡号唯一，不能重复
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    身份证号
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="identity" required="" autocomplete="off" class="layui-input" value="{$data.identity|default=''}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    手机号
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" required="" autocomplete="off" class="layui-input" value="{$data.phone|default=''}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    开户人
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="name" required="" autocomplete="off" class="layui-input" value="{$data.name|default=''}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    是否默认
                </label>
                <div class="layui-input-inline">
                    {if !isset($data['is_default'])}
                    <input type="radio" name="is_default" value="1" title="是" checked>
                    <input type="radio" name="is_default" value="0" title="否">
                    {else /}
                    <input type="radio" name="is_default" value="1" title="是" {if $data['is_default'] == 1}checked{/if}>
                    <input type="radio" name="is_default" value="0" title="否" {if $data['is_default'] == 0}checked{/if}>
                    {/if}
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">确定保存</button></div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer','jquery'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //监听提交
        form.on('submit(add)', function(data) {
            $.ajax({
                url:"{:url('Users/bank_edit')}",
                type: "post",
                data:data.field,
                dataType:"json",
                success:function (res) {
                    if(res.code == 200){
                        layer.alert(res.msg, {icon: 1},function () {
                            //关闭当前frame
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });
                    }else{
                        layer.alert(res.msg, {icon:2,time:1000});
                    }
                },
                error:function(e){
                    layer.alert("网络错误", {icon:5,time:1000});
                },
            });
            return false;
        });
    });


window.onload = function(){
    imgUrlInput()
}

// 更改图片拼接地址
function imgUrlInput(imgInput = 'img', path = '/newUploads'){
    // 获取到图片url
    var imgUrl = $("input[name="+imgInput+"]").val()
    var index =  imgUrl.indexOf(location.origin)
    if(index >= 0){
        $("input[name="+imgInput+"]").val(imgUrl.split(location.origin + path)[1])
    }
}



    //添加属性
    function attr_add(obj){
        var html = '';
        html += '<tr>';
        html += '<td style="width:90%;">';
        html += '<input type="text" name="desc[]" required="" autocomplete="off" class="layui-input" value="">';
        html += '</td>';
        html += '<td style="width:10%;text-align: center">';
        html += '<a href="javascript:;" onclick="attr_del(this)">';
        html += '<i class="iconfont">&#xe6fe;</i>删除';
        html += '</a>';
        html += '</td>';
        html += '</tr>';

        $(obj).parents("tr").parents('tbody').append(html);
    }

    //删除属性
    function attr_del(obj){
        $(obj).parents("tr").remove();
    }

//按钮-进行上传操作--图片阅览
$('#test1').click(function(){
    $('#test1s').click();
})

// 操作成功后的回调
$('#test1s').change(function(e){
    var imgBox = e.target;
    if(imgBox.files[0].size > 1024 * 1024 *2){
        return layer.msg('失败，文件不得超过2mb',{icon: 5})
    }
    var img = getObjectURL(imgBox.files[0]);
    $('#img').attr('src',img);
    var data = {image: imgBox.files[0]}
    var formData = new FormData();
    formData.append('image', imgBox.files[0]);
    formData.append('prefix','levelBanner');
    $.ajax({
        url:"{:url('admin/uploads/uploadImg')}",
        type: 'post',
        async: false,
        data: formData,
        dataType: 'json',
        processData: false,// 告诉jQuery不要去处理发送的数据
        contentType: false,// 告诉jQuery不要去设置Content-Type请求头
        beforeSend: function (){ //过程...
        },
        success: function (res) {
            console.log(res.data)
            if (res.code == 200) {
                layer.msg('加载成功', {icon: 6})
                //$('input[name=img_url]').val(HOST_URL +'/' +  res.data.fileName + '/' + (res.data.prefix ? '/' +  res.data.prefix + '/' : '') + res.data.url.replace("\\",'/'))
                $('input[name=img]').val( (res.data.prefix ? '/' +  res.data.prefix + '/' : '') + res.data.url.replace("\\",'/'))
            } else {
                layer.msg(res.msg || '失败，麻烦重新尝试', {icon: 5})
            }
        },
        error:function(){
            layer.msg( '失败，重新尝试，多次失败后麻烦联系开发人员', {icon: 5})
        }
    })
});

//建立一個可存取到該file的url
function getObjectURL(file) {
    var url;
    if (window.createObjectURL != undefined) { // basic
        url = window.createObjectURL(file);
    } else if (window.URL != undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file);
    } else if (window.webkitURL != undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file);
    }
    return url;
}
</script>
{include file='common/footer' /}